<%--
  User: Shengzhao Li
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>事情</title>
</head>
<body>
<%--thing form page--%>
<div id="thing_form_page" data-role="page" class="page">
    <div data-role="header" data-theme="f">
        <a href="${contextPath}/m/dashboard" data-icon="home" data-direction="reverse"
           data-transition="slide">主页</a>

        <h1>事情</h1>
        <a href="javascript:void(0);" data-icon="arrow-l" data-rel="back">返回</a>
    </div>
    <div data-role="content">
        <div class="center red" style="display: none;" id="save_info">保存成功!</div>
        <form:form commandName="thingDto" id="thing_form" data-ajax="false" onsubmit="$.mobile.showPageLoadingMsg();">
            <form:hidden path="status"/>
            <ul data-role="listview" data-inset="true">
                <li>
                    <div data-role="fieldcontain">
                        <label for="event">事件:</label>
                        <form:select path="eventGuid" data-native-menu="false" id="event">
                            <form:option value="" label="-- 无 --"/>
                            <c:forEach items="${thingDto.availableEvents}" var="e">
                                <form:option value="${e.guid}" label="${e.name}"/>
                            </c:forEach>
                        </form:select>
                        <form:errors path="eventGuid" cssClass="form_error"/>
                    </div>
                    <div data-role="fieldcontain">
                        <label for="priority">优先级:</label>
                        <form:select path="priority" id="priority" items="${thingDto.priorities}" itemLabel="label"
                                     itemValue="value" data-native-menu="false"/>
                    </div>
                    <div data-role="fieldcontain">
                        <label for="startDate">开始日期:</label>
                        <form:input id="startDate" path="startDate" placeholder="开始日期(可选)"/>
                    </div>
                    <div data-role="fieldcontain">
                        <label for="content">内容:</label>
                        <form:textarea path="content" placeholder="请输入事情的内容" id="content"/>
                        <form:errors path="content" cssClass="form_error"/>
                    </div>
                </li>
                <li>
                    <div data-role="fieldcontain">
                        <input type="hidden" name="addNext" value="false" id="add_next"/>
                        <button type="submit" data-theme="b" data-icon="plus">保存</button>
                        <a data-theme="b" data-icon="plus" data-role="button"
                           href="javascript:saveAndNext();">保存&继续添加</a>
                        <a href="overview" data-theme="c" data-icon="delete" data-role="button"
                           data-direction="reverse" data-transition="flip">取消</a>
                    </div>
                </li>
            </ul>
        </form:form>
    </div>
    <script type="text/javascript">
        $(function() {
            <c:if test="${param.added}">
            $("#save_info").fadeIn(800).delay(800).fadeOut(800);
            </c:if>
        });

        function saveAndNext() {
            $("#add_next").val('true');
            $("#thing_form").submit();
        }

        $("#thing_form_page").live("pagecreate", function() {
            $("#startDate").scroller({
                preset: 'date',
                dateFormat: 'yy-mm-dd',
                dateOrder: 'ymmdd',
                theme:"jqm",
                lang:"zh",
                animate:"flip"
            });
        });
    </script>
</div>
</body>
</html>